package AndroidHT.Workspace;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class WelcomeActivity extends Activity {

	public static String Welcome = "Welcome:";
	
	/** Called when the activity is first created. */
    Context appContext;
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {

		
		Log.i(Welcome,"Dentro OnCreate");
		
		appContext = this.getApplicationContext();
		
		super.onCreate(savedInstanceState);	
	    setContentView(R.layout.welcome);    

	    Log.i(Welcome,"Dentro Content");
	    
	    Button button = (Button) findViewById(R.id.buttonIngresar);
	   
	    button.setOnClickListener(new OnClickListener()
	    {     

			public void onClick(View v) {
				
				Log.i(Welcome,"Dentro OnClick");
				
				SharedPreferences settings = getSharedPreferences("HT",MODE_PRIVATE);			   
				SharedPreferences.Editor editor = settings.edit();
			    EditText mail = (EditText) findViewById(R.id.editTextMail);
			    EditText user = (EditText) findViewById(R.id.EditTextNuevoUsuario);
			    EditText pass = (EditText) findViewById(R.id.editTextNuevoPassword);
			    EditText confirmPass = (EditText) findViewById(R.id.EditTextConfimaNuevoPassword);
			    Log.i(Welcome,"Pass="+pass.getText().toString()+" - "+"Confirm Pass"+confirmPass.getText().toString());
			    if(pass.getText().toString().compareTo(confirmPass.getText().toString()) != 0)
			    {
			    	Toast.makeText(appContext,"Los passwords ingresados no coinciden",Toast.LENGTH_SHORT).show();
			    }
			    else
			    {
			    	Toast.makeText(appContext,"Mail ingresado: "+mail.getText().toString(),Toast.LENGTH_SHORT).show();
					  
				    
				    editor.putString("HT_Start", "OK" );	
				    
					editor.putString("HT_Email", mail.getText().toString() );
					editor.putString("HT_User", user.getText().toString() );
					editor.putString("HT_Password", pass.getText().toString() );
					
					editor.commit();
					
					startActivity(new Intent(appContext,AndroidHTActivity.class));
		
			    }
			    	    			
			}
	    });
	 
	}
	@Override
	protected void onStop() {
		
		super.onStop();
	}
}
